//
//  LKMyUpdateCustomerCheckResultViewController.m
//  YLHelper
//
//  Created by she1323 on 2018/5/11.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKMyUpdateCustomerCheckResultViewController.h"
#import "LKWriteContinuInvestCell.h"
#import "LKMyDescriptionCell.h"
#import "LKTestpageNameTitleCell.h"
@interface LKMyUpdateCustomerCheckResultViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)LKBaseTableview *tableView;
@property(nonatomic,strong)NSArray *titlesArray;

@end

@implementation LKMyUpdateCustomerCheckResultViewController
-(LKBaseTableview *)tableView{
    if (!_tableView) {
        _tableView = [LKBaseTableview setTableviewWithFrame:CGRectMake(0, 12 + NAVIGATION_BAR_HEIGHT, WIDTH, HEIGHT - (NAVIGATION_BAR_HEIGHT + 12)) style:UITableViewStyleGrouped registercellClasss:@[@"LKTestpageNameTitleCell",@"LKWriteContinuInvestCell",@"LKMyDescriptionCell"]];
        [self.view addSubview:_tableView];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.estimatedRowHeight = 200;
    [self getAlreadyCheckResultInformation];
    // Do any additional setup after loading the view.
}
-(void)setNavgationBackBtn{
    [super setNavgationBackBtn];
    self.navigationItem.title = @"客户归属变更审批";
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 6;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0 || indexPath.section == 1 || indexPath.section == 2) {
        LKWriteContinuInvestCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKWriteContinuInvestCell"];
        cell.arrowIcon.hidden = YES;
        cell.titleLabel.text = self.titlesArray[indexPath.section];
        return cell;
    }
    LKTestpageNameTitleCell *cell = [tableView dequeueReusableCellWithIdentifier:@"LKTestpageNameTitleCell"];
    cell.titleLabel.text = self.titlesArray[indexPath.section];
    if (indexPath.section == self.titlesArray.count - 1) {
        cell.contentLabel.text = self.suggestStr;
        cell.contentLabel.textAlignment = NSTextAlignmentCenter;
        cell.contentLabel.textColor = ColorRGB(14, 130, 5);
        cell.contentLabel.font = [UIFont systemFontOfSize:15];
    }
    NSString *remark = [NSString stringWithFormat:@"%@",[NSString judegeIsNullAndTransform:self.approvModel.changeRemark]];
    NSString *suggestStr = [NSString stringWithFormat:@"%@",[NSString judegeIsNullAndTransform:self.approvModel.approvalContent]];
    NSString *result = [self backTitleAccoringStatus:self.approvModel.status];
    NSArray *arr = @[remark,suggestStr,result];
    cell.contentLabel.text = arr[indexPath.section - 3];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 3 ||  indexPath.section == 4   ) {
        return UITableViewAutomaticDimension;
    }
    return indexPath.section == 5 ? 95 : 43;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.0000000000001;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 12;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [[UIView alloc] init];
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = cellHeaderBgColor;
    return view;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
-(NSArray *)titlesArray{
    if (!_titlesArray) {
        NSString *customerName = [NSString stringWithFormat:@"变更客户：%@",self.approvModel.customerName];
        NSString *foremanger = [NSString stringWithFormat:@"原客户经理：%@",self.approvModel.beforeContext];
        NSString *aftermanaer = [NSString stringWithFormat:@"新客户经理：%@",self.approvModel.afterContext];
        _titlesArray = @[customerName,foremanger,aftermanaer,@"备注",@"审批意见",@"审批结果"];
    }
    return _titlesArray;
}
-(NSString *)backApproveStatus:(NSInteger)type{
    if (type == 0) {
        return @"待审批";
    }else if(type == 1){
        return @"审批通过";
    }else if(type == -1){
        return @"审批未通过";
    }else{
           return @"";
    }

}

/**
 获取已经审批过的详情
 */
-(void)getAlreadyCheckResultInformation{
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:getMyAlreadyCheckDetailUrl header:[LKUserInforTool header] parameters:@{@"Id":self.approvModel.applyId} progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        self.approvModel = [LKApprovaModel modelWithDictionary:responseObject[@"result"]];
        NSString *customerName = [NSString stringWithFormat:@"变更客户：%@",self.approvModel.customerName];
        NSString *foremanger = [NSString stringWithFormat:@"原客户经理：%@",self.approvModel.beforeContext];
        NSString *aftermanaer = [NSString stringWithFormat:@"新客户经理：%@",self.approvModel.afterContext];
        self.titlesArray = @[customerName,foremanger,aftermanaer,@"备注",@"审批意见",@"审批结果"];
        [self.tableView reloadData];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}

/**
 根据状态的值返回对应的文字

 @param status 状态值
 @return 对应的文字
 */
-(NSString *)backTitleAccoringStatus:(NSString *)status{
    if ([status integerValue] == 0) {
        return @"待审批";
    }else if ([status integerValue] == 3){
       return @"分总审批通过";
    }else if ([status integerValue] == -3){
        return @"分总审批未通过";
    }else if ([status integerValue] == 1){
        return @"客服审批通过";
    }else if ([status integerValue] == -1){
        return @"客服审批未通过";
    }else{
        return @"";
    }
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
